package com.hejian.android.a72ggametools.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.Toast;

import com.hejian.android.a72ggametools.R;
import com.hejian.android.a72ggametools.utils.CommonUtils;

/**
 * Created by Administrator on 2016/1/14.
 */
public class RegisterActivity extends AppCompatActivity implements View.OnClickListener {
    private Button backBtn;
    private EditText phoneEdt;
    private EditText nickNameEdt;
    private EditText passwordEdt;
    private CheckBox readCheckBox;
    private Button nextBtn;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_register);
        initView();
        setListener();
    }

    private void setListener() {
        backBtn.setOnClickListener(this);
        nextBtn.setOnClickListener(this);

    }

    private void initView() {
        backBtn = (Button)findViewById(R.id.register_back);
        phoneEdt = (EditText)findViewById(R.id.register_user_name);
        nickNameEdt = (EditText)findViewById(R.id.register_user_nick);
        passwordEdt  = (EditText)findViewById(R.id.register_user_password);
        readCheckBox = (CheckBox)findViewById(R.id.register_checkbox_read_and_receive);
        nextBtn = (Button)findViewById(R.id.register_next_btn);

    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.register_back:
                finish();
                break;
            case R.id.register_next_btn:
                String userName = phoneEdt.getText().toString();
                String nickName = nickNameEdt.getText().toString();
                String password = passwordEdt.getText().toString();
                if (userName == null ||userName.length() == 0
                        || nickName == null ||nickName.length() ==0
                        || password == null || password.length() ==0) {
                    Toast.makeText(RegisterActivity.this, "您输入的信息不完整", Toast.LENGTH_LONG).show();
                } else if (!readCheckBox.isChecked()){
                    Toast.makeText(RegisterActivity.this, "请详细阅读注册协议", Toast.LENGTH_LONG).show();
                } else if (!CommonUtils.isMobileNO(userName)){
                    Toast.makeText(RegisterActivity.this, "请输入正确的手机号码", Toast.LENGTH_LONG).show();
                } else if (password.length() <8){
                    Toast.makeText(RegisterActivity.this, "密码不能少于八位", Toast.LENGTH_LONG).show();
                } else {
                    Intent intent = new Intent(RegisterActivity.this,PhoneNumCheckActivity.class);
                    intent.putExtra("username",userName);
                    intent.putExtra("nickname",nickName);
                    intent.putExtra("password",password);
                    intent.putExtra("sign","fromregister");
                    startActivity(intent);
                }
                break;
        }
    }

}
